package com.novelot.plugin.allinone;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import org.jetbrains.annotations.NotNull;

public class MyToolWindowFactory implements ToolWindowFactory {

    @Override
    public boolean isApplicable(@NotNull Project project) {
        return true;//必须为true
    }

    @Override
    public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
//        toolWindow.setToHideOnEmptyContent(true);
//        toolWindow.setStripeTitle("Nove-Plugin");
//        @Nullable JComponent panel = new JPanel();
//        JLabel label = new JLabel("Nove-Plugin-Label");
//        panel.add(label);
//        @NotNull Content content = ContentFactory.SERVICE.getInstance().createContent(panel, "", false);
//        toolWindow.getContentManager().addContent(content);
//        toolWindow.setShowStripeButton(true);
//        toolWindow.setTitle("Nove-Plugin-Toolwindow-Title");
//        toolWindow.show();

        // 初始化自定义组件对象
        MyToolWindow myToolWindow = new MyToolWindow(project, toolWindow);

        // 组件添加到AS中
        ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
        Content content = contentFactory.createContent(myToolWindow.getContent(), "", false);
        toolWindow.getContentManager().addContent(content);
    }

    @Override
    public void init(@NotNull ToolWindow toolWindow) {

    }

    @Override
    public boolean shouldBeAvailable(@NotNull Project project) {
        return true;//必须为true
    }

    @Override
    public boolean isDoNotActivateOnStart() {
        return false;
    }

}
